﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>@*
<script src="~/lib/layuiadmin/layui/layui.js"></script>
<script src="~/lib/layuiadmin/config.js"></script>
<link href="~/lib/layuiadmin/layui/css/layui.css" rel="stylesheet" /> *@



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    @* <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet"> *@
</head>
<body>
    
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <div class="layui-inline">

                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text"  id="userName" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                     <div class="layui-form-mid" style="padding: 0!important;">
                        <button type="button" class="layui-btn" onclick="Updateuname()">
                            修改
                        </button>

                        
                    </div>

                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text"  id="userNames" lay-verify="required" autocomplete="off" lay-reqtext="请输入用户名" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                     <button type="button" class="layui-btn" onclick="Getuname">
                         确定
                     </button>

                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-block">
                        <input type="text" id="userNikeName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">单选框</label>
                    <div class="layui-input-block">
                        <input type="radio" name="userSex" value="男" title="男">
                        <input type="radio" name="userSex" value="女" title="女">
                        <input type="radio" name="userSex" value="禁" title="禁用" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" id="userRealName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">证件类型</label>
                    <div class="layui-input-block">
                        <select name="city" id="userCardType" lay-filter="aihao">
                            <option value="">请选择证件类型</option>
                            <option value="身份证">身份证</option>
                            <option value="护照">护照</option>
                            <option value="军官证">军官证</option>
                            <option value="士兵证">士兵证</option>
                            <option value="港澳台往来通行证">港澳台往来通行证</option>
                            <option value="警官证">警官证</option>
                            <option value="外国人永久居留证">外国人永久居留证</option>
                            <option value="边民出入通行证">边民出入通行证</option>
                            <option value="其他">其他</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">证件号码</label>
                    <div class="layui-input-block">
                        <input type="text" id="userCard" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机号码</label>
                    <div class="layui-input-block">
                        <input type="text" id="userPhone" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">电子邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" id="userEmail" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">所在地</label>
                    <div class="layui-input-block">
                        <input type="text" id="userAddress" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-submit lay-filter="demo1" onclick="AddLogin()">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

            </div>
        </div>
    </form>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;

        });
    </script>
</body>
</html>

<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;

        FanT();

        //反填
        function FanT() {
            var userId = localStorage.getItem("userId")
            console.log(userId)
            $.post({
                url: "http://localhost:5123/api/UsersInterface/UserInfoBackFill",
                data:
                    JSON.stringify({
                        UserId: userId
                    }),

                async: false,
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    console.log(res.data)
                    $(res.data).each(function () {
                        $("#userName").val(this.userName)
                        $("#userNikeName").val(this.userNikeName)
                        $("[name=userSex][value=" + this.userSex + "]").prop("checked", true)
                        $("#userRealName").val(this.userRealName)

                        $("#userCard").val(this.userCard)
                        $("#userPhone").val(this.userPhone)
                        $("#userEmail").val(this.userEmail)
                        $("#userAddress").val(this.userAddress)
                        $("#userCardType").val(this.userCardType)
                        form.render('select');
                    })
                }

            })
        }
        console.log(2222);
        

    });


    //修改
    function Updateuname() {
        console.log(123);
        var userNames = $("#userNames").val()
        var userId = localStorage.getItem("userId")
        $.post({
            url: 'http://localhost:5123/api/UsersInterface/UpdateUserName',
            data: JSON.stringify({ UserId: userId, userName: userNames }),
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg);
                    location.href='/User/AddUser'
                }
                else if (res.code == 2) {
                    layer.msg(res.msg);
                }
                else {
                    layer.msg(res.msg);
                }
            }

        })

    }
</script>
